package com.net;

public class RandomThread {
  public static void main(String[] args) {
    try {
      MyRandomThread thread = new MyRandomThread();

      thread.setName("myRandomThread");
      thread.start();

      for (int i=0, length=10; i<length; i++) {
        int time = (int) (Math.random() * 1000);
        Thread.sleep(time);

        System.out.println("main:" + i + " " +Thread.currentThread().getName());
      }

    } catch (Exception e) {

    }
  }
}

class MyRandomThread extends Thread {
  @Override
  public void run() {

    try {
      for (int i=0,lenth=10; i<lenth; i++){
        int time = (int) (Math.random() * 1000);

        Thread.sleep(time);
        System.out.println(" run:" + i +" " + Thread.currentThread().getName());
      }

    } catch (Exception e) {
      e.printStackTrace();
    }

  }
}
